﻿#region File Description
/****************************************************************************
*                                                                           *
* Main Menu Screen.                                                         *
*                                                                           *
* Copyright (c) Ionescu Marius. All rights reserved(2010).                  *
*                                                                           *
****************************************************************************/
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
#endregion

namespace XNA_FRAMEWORK
{
    class XNAMainMenuScreen : XNAMenuScreen
    {
        #region Initialization

        public XNAMainMenuScreen()
            : base("Main Menu")
        {
            XNAMenuEntry playGameMenuEntry = new XNAMenuEntry("Play Game");
			XNAMenuEntry customMenuEntry = new XNAMenuEntry("Custom");
            XNAMenuEntry optionsMenuEntry = new XNAMenuEntry("Options");
            XNAMenuEntry exitMenuEntry = new XNAMenuEntry("Exit");

            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
			customMenuEntry.Selected += CustomMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            MenuEntries.Add(playGameMenuEntry);
			MenuEntries.Add(customMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        #endregion

        #region Handle Input

        void PlayGameMenuEntrySelected(object sender, XNAPlayerIndexEventArgs e)
        {
            XNALoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
                               new XNAGameplayScreen());
        }

		void CustomMenuEntrySelected(object sender, XNAPlayerIndexEventArgs e)
		{
			XNALoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
							   new XNACustomScreen());
		}

        void OptionsMenuEntrySelected(object sender, XNAPlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new XNAOptionsMenuScreen(), e.PlayerIndex);
        }

        protected override void OnCancel(PlayerIndex playerIndex)
        {
            const string message = "Are you sure you want to exit this sample?";

            XNAMessageBoxScreen confirmExitMessageBox = new XNAMessageBoxScreen(message);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
        }

        void ConfirmExitMessageBoxAccepted(object sender, XNAPlayerIndexEventArgs e)
        {
            ScreenManager.Game.Exit();
        }

        #endregion
    }
}
